package com.project.service;

import com.project.common.utils.MyPageHelper;
import com.project.dao.PaperShareMapper;

import com.project.entity.ExamPaper;
import com.project.entity.PaperShare;
import com.project.service.base.BaseService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

@Transactional(rollbackFor = Exception.class)
@Service
public class PaperShareServiceImpl extends BaseService implements PaperShareService {

    @Autowired
    PaperShareMapper paperShareMapper;

    @Override
    public List<PaperShare> findByTeacherid(Integer teacherid){
        return paperShareMapper.selectByTeacherid(teacherid);
    }

    @Override
    public void add(PaperShare paperShare){
          paperShareMapper.insert(paperShare);
    }

    @Override
    public List<PaperShare> findByexamPaperid(Integer examPaperid) {
        return paperShareMapper.selectBypapershareid(examPaperid);
    }

    @Override
    public void addBatch(List<Integer> shareteacheridlist, Integer examPaperid) {
        paperShareMapper.deleteByexamPaperid(examPaperid);
        for (Integer papershareid : shareteacheridlist) {
            PaperShare tmp = new PaperShare();
            tmp.setExampaperid(examPaperid);
            tmp.setTeacherid(papershareid);
            paperShareMapper.insert(tmp);
        }
    }
}
